﻿using Net5ApiANdWpfClient.Lib.Common;
using Net5ApiANdWpfClient.Lib.Model;
using Net5ApiANdWpfClient.Lib.Model.SystemAdmin;
using Net5ApiANdWpfClient.Lib.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfClient.SystemManger
{
    /// <summary>
    /// positioninfo.xaml 的交互逻辑
    /// </summary>
    public partial class positioninfo : BaseUserControl
    {
        public positioninfo()
        { 
            InitializeComponent();
            adminUserPage.PageSize = PcConfig.PageSize;
            adminUserPage.PageCurrent = 1;
            Search();
        }
        public int Search()//显示
        {
            string po_name = un.Text;
            PagerResult<Net5ApiANdWpfClient.Lib.Model.SystemAdmin.positioninfo> result = new positioninfoService().SearchPage(po_name, adminUserPage.PageCurrent);
            if (result != null)
            {
                userList.DataContext = result.Data;
                adminUserPage.NMax = result.recordsTotal;
                return result.recordsTotal;
            }
            return 0;
        }

        private void AddBtn_Click(object sender, RoutedEventArgs e)//添加
        {
            PositioninfoAdd main = new PositioninfoAdd();
            main.Show();
            
        }

        private void SearchBtn_Click(object sender, RoutedEventArgs e)//查询
        {
            Search();

        }
        private void UserDeleteClick(object sender, RoutedEventArgs e)//删除
        {
            Button btn = sender as Button;
            MessageBoxResult dr = MessageBox.Show("是否在" + ("Charge") + "库执行sql", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
            if(dr==MessageBoxResult.OK)
            {
                if(btn!=null)
                {
                    positioninfoService infoDel = new positioninfoService();
                    int id = (int)btn.Tag;
                    bool a = infoDel.positioninfoDel(id);
                    if(a)
                    {
                        MessageBox.Show("删除成功");
                        Search();
                    }
                    else
                    {
                        MessageBox.Show("删除失败");
                    }
                }
            }
        }
        public static int Ppo_ids { get; set; }
        private void UserUpdate(object sender, RoutedEventArgs e)//修改
         {
            Button btn = sender as Button;
            int id = (int)btn.Tag;
            Ppo_ids = id;
            PositioninfoUpdate infoupdate = new PositioninfoUpdate();
            infoupdate.Show();
        }
        private int AdminUserPage_EventPaging(Common.EventPagingArg e)
        {
            return Search();
        }
    }
}
